﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using ReactiveUI;

namespace 多视图导航.ViewModels
{

    public enum Page
    {
        Home,
        Nav,
        Config
    }
    public partial class MainViewModel : ViewModelBase
    {
        public ReactiveCommand<Unit, Unit> GotoHomeCommand { get; }
        public ReactiveCommand<Unit, Unit> GotoNavCommand { get; }
        public ReactiveCommand<Unit, Unit> GotoConfigCommand { get; }
        public MainViewModel()
        {
            GotoHomeCommand = ReactiveCommand.Create(()=>GotoPageExecute(Page.Home));
            GotoNavCommand = ReactiveCommand.Create(() => GotoPageExecute(Page.Nav));
            GotoConfigCommand = ReactiveCommand.Create(() => GotoPageExecute(Page.Config));
            _CurrentPage = Pages[Page.Home];
        }


        private PageViewModelBase _CurrentPage;
        private readonly Dictionary<Page, PageViewModelBase> Pages = new Dictionary<Page, PageViewModelBase>
        {
            { Page.Home, new HomeViewModel() },
            { Page.Nav, new NavViewModel() },
            { Page.Config, new ConfigViewModel() },
        };
        public PageViewModelBase CurrentPage
        {
            get { return _CurrentPage; }
            private set { this.RaiseAndSetIfChanged(ref _CurrentPage, value); }
        }
        private void GotoPageExecute(Page page)
        {
            if (Pages.TryGetValue(page, out var pageViewModel))
            {
                CurrentPage = pageViewModel;
            }
        }
    }
}
